package com.r_z.service.impl;

import org.springframework.stereotype.Service;
import com.r_z.entity.FinancialRevenue;
import com.r_z.mapper.FinancialRevenueMapper;
import com.r_z.service.FinancialRevenueService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 财务收入
 * @author :yimeng
 * @date :2023/5/30  8:53
 * @description:some description
 */
@Service
public class FinancialRevenueServiceImpl implements FinancialRevenueService {
    @Resource
    FinancialRevenueMapper financialRevenueMapper;

    /**
     * 根据主键ID查询财务信息
     * @param fRevenueId
     * @return
     */
    @Override
    public List<FinancialRevenue> selectAllFinancialRevenue(String fRevenueId) {
        return financialRevenueMapper.selectAllFinancialRevenue(fRevenueId);
    }

    /**
     * 根据条件分页查询
     * @param page 当前页
     * @param limit 每页显示数
     * @param financialRevenue
     * @return
     */
    @Override
    public List<FinancialRevenue> LimitFinancialRevenue(int page,int limit,FinancialRevenue financialRevenue) {
        Map map = new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("strWhere",buildStrWhere(financialRevenue));
        return financialRevenueMapper.LimitFinancialRevenue(map);
    }

    /**
     * 根据条件查询总行数
     * @param financialRevenue
     * @return
     */
    @Override
    public int countFinancialRevenue(FinancialRevenue financialRevenue) {
        Map map = new HashMap();
        map.put("strWhere",buildStrWhere(financialRevenue));
        int count = financialRevenueMapper.countFinancialRevenue(map);
        return count;
    }

    /**
     * 添加财务收入信息
     * @param financialRevenue
     * @return
     */
    @Override
    public int insertFinancialRevenue(FinancialRevenue financialRevenue) {
        return financialRevenueMapper.insertFinancialRevenue(financialRevenue);
    }

    /**
     * 根据主键ID进行删除财务收入信息
     * @param fRevenueId
     * @return
     */
    @Override
    public int deleteFinancialRevenue(String fRevenueId) {
        return financialRevenueMapper.deleteFinancialRevenue(fRevenueId);
    }

    /**
     * 批量删除
     * @param fRevenueId
     * @return
     */
    @Override
    public int deleteFinancialRevenueById(String fRevenueId) {
        //转数据
        String[] split = fRevenueId.split(",");
        //创建存放id的集合
        ArrayList<Object> objects = new ArrayList<>();
        for (String id : split){
            //将id存入集合
            objects.add(id);
        }
        return financialRevenueMapper.deleteFinancialRevenueById(objects);
    }

    /**
     * 根据主键ID进行修改财务收入信息
     * @param financialRevenue
     * @return
     */
    @Override
    public int updateFinancialRevenue(FinancialRevenue financialRevenue) {
        return financialRevenueMapper.updateFinancialRevenue(financialRevenue);
    }


    /**
     * 生成条件字符串
     * @param financialRevenue 生成条件的参数
     * @return 条件字符串  and fundId like '%%'
     */
    public String buildStrWhere(FinancialRevenue financialRevenue){
        StringBuffer strWhere = new StringBuffer("");
        if(financialRevenue.getFRevenueId()!=null && !financialRevenue.getFRevenueId().equals(""))
        {
            strWhere.append(" and fRevenueId like '%"+financialRevenue.getFRevenueId ()+"%'");
        }
        return  strWhere.toString();
    }
}
